//端口
var PortODF = {
    port_bg_url : 'imgs/odf-port-bg.png',
    fontFamily:'Courier New',
    fontSize:22,
    fontColor: '#ffffff',
    width: 276,//接口宽度
    height:79,//接口高度
    bodyBackground:'#a1c4c0',
    createNew: function(id, name){//名称
        var port = {};
        port.x=0;
        port.y=0;
        port.id = id;
        port.name = name;
        port.getLeftConnectorPos = function(){
            var x = 0, y = 0;
            x = this.x - 2;
            y = this.y + PortODF.height / 2;
            return {x:x,y:y};
        };
        port.getRightConnectorPos = function(){
            var x = 0, y = 0;
            x = this.x + PortODF.width + 2;
            y = this.y + PortODF.height / 2;
            return {x:x,y:y};
        };
        port.draw = function(canvas){
            PortODF.draw(this,canvas);
        }
        return port;
    },
    draw : function(obj, canvas){
        var bgImg = new Image();
        bgImg.src = PortODF.port_bg_url;
        if(bgImg.complete){
            PortODF._draw(obj,canvas,bgImg);
        }else{
            bgImg.onload = function(){
                PortODF._draw(obj,canvas,bgImg);
            }
        }
    },
    _draw : function(obj, canvas,bgImg){
        //底图
        canvas.drawImage(bgImg,obj.x, obj.y,PortODF.width,PortODF.height);
        //画出名字
        canvas.font = PortODF.fontSize + "px " + PortODF.fontFamily;
        canvas.fillStyle = PortODF.fontColor;
        canvas.textAlign="center";
        canvas.fillText(obj.name,obj.x + PortODF.width / 2, obj.y + (PortODF.height + PortODF.fontSize) / 2 - 2 , PortODF.width);
    }
};